package com.TIEmulator.FileIOLib;

import android.content.Context;
import android.content.res.AssetManager;
import android.util.Log;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

public final class FileIOLib
{
  private static String LOG_ID = "FileIOLib";
  private static String io_base_dir_internal = null;

  public static String GetBaseDir()
  {
    return io_base_dir_internal;
  }

  public static boolean checkEndsWithInStringArray(String paramString, String[] paramArrayOfString)
  {
    int i = paramArrayOfString.length;
    for (int j = 0; ; ++j)
    {
      if (j >= i);
      for (int k = 0; ; k = 1)
      {
        return k;
        if (!(paramString.endsWith(paramArrayOfString[j])))
          break;
      }
    }
  }

  public static boolean copyAssetFileToPkgDir(Context paramContext, String paramString)
  {
    int i;
    if (io_base_dir_internal == null)
    {
      Log.e(LOG_ID, "copyAssetFileToPkgDir error: <you have to call setupFromMain first>");
      i = 0;
    }
    while (true)
    {
      return i;
      AssetManager localAssetManager = paramContext.getAssets();
      try
      {
        InputStream localInputStream = localAssetManager.open(paramString, 3);
        byte[] arrayOfByte = new byte[localInputStream.available()];
        localInputStream.read(arrayOfByte);
        localInputStream.close();
        File localFile = new File(io_base_dir_internal + "/" + paramString);
        createAbsoluteFileDir(localFile);
        FileOutputStream localFileOutputStream = new FileOutputStream(localFile);
        localFileOutputStream.write(arrayOfByte);
        localFileOutputStream.close();
        i = 1;
      }
      catch (IOException localIOException)
      {
        localIOException.printStackTrace();
        i = 0;
      }
    }
  }

  public static void createAbsoluteFileDir(File paramFile)
  {
    new File(paramFile.getParent()).mkdir();
  }

  public static String getAbsolutePkgDir()
  {
    return io_base_dir_internal;
  }

  public static List<String> searchImgFilesInPath(String paramString)
  {
    ArrayList localArrayList = new ArrayList();
    int i;
    int j;
    label70: 
    do
      try
      {
        File[] arrayOfFile = new File(paramString).listFiles(new TIEmuExt());
        if (arrayOfFile.length <= 0)
          break label77;
        i = arrayOfFile.length;
        j = 0;
        break label70:
        localArrayList.add(arrayOfFile[j].getName());
        ++j;
      }
      catch (NullPointerException localNullPointerException)
      {
        localNullPointerException.printStackTrace();
        break label77:
      }
    while (j < i);
    label77: return localArrayList;
  }

  public static void setupFromMain(Context paramContext)
  {
    io_base_dir_internal = "/data/data/" + paramContext.getClass().getPackage().getName();
  }

  public static boolean validateFnPath(String paramString)
  {
    return new File(paramString).exists();
  }

  public static class TIEmuExt
    implements FilenameFilter
  {
    public boolean accept(File paramFile, String paramString)
    {
      String str = paramString.toLowerCase();
      if ((str.endsWith(".v2u")) || (str.endsWith(".89u")) || (str.endsWith(".9xu")) || (str.endsWith(".img")) || (str.endsWith(".rom")) || (str.endsWith(".tib")));
      for (int i = 1; ; i = 0)
        return i;
    }
  }
}
